<?php

namespace App\Filament\Resources;

use App\Filament\Resources\ComponentTypeResource\Pages;
use App\Filament\Resources\ComponentTypeResource\RelationManagers;
use App\Models\ComponentType;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use App\Models\Component;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Components\Repeater;
use Filament\Tables\Columns\TextColumn;

class ComponentTypeResource extends Resource
{
    protected static ?string $model = ComponentType::class;

    protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                 TextInput::make('name'),
                 Textarea::make('description'),
                    Select::make('category')->options(
                        ['frontend' => 'frontend', 'backend' => 'backend']
                    )->required(),
                Select::make('component_id')
                ->label('Component')
                ->options(Component::all()->pluck('title', 'id'))
                ->searchable(),
                Repeater::make('dependencies')
                    ->schema([
                        TextInput::make('name')->required(),
                        TextInput::make('version')->required(),
                        TextInput::make('cdn_url'),
                        Select::make('order')->options(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']),
                        Select::make('location')->options(['head' => 'head', 'footer' => 'footer']),
                    ]),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('name'),
            ])
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\EditAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ]);
    }

    public static function getRelations(): array
    {
        return [
            //
        ];
    }

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListComponentTypes::route('/'),
            'create' => Pages\CreateComponentType::route('/create'),
            'edit' => Pages\EditComponentType::route('/{record}/edit'),
        ];
    }
}
